#
# Copyright 2023 The Kumo Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
############################################################
# system pthread and rt, dl
############################################################
set(KMCMAKE_SYSTEM_DYLINK)
if (APPLE)
    find_library(CoreFoundation CoreFoundation)
    list(APPEND KMCMAKE_SYSTEM_DYLINK ${CoreFoundation} pthread)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
    list(APPEND KMCMAKE_SYSTEM_DYLINK rt dl pthread)
endif ()

if (KMCMAKE_BUILD_TEST)
    enable_testing()
    #include(require_gtest)
    #include(require_gmock)
    #include(require_doctest)
endif (KMCMAKE_BUILD_TEST)

if (KMCMAKE_BUILD_BENCHMARK)
    #include(require_benchmark)
endif ()

find_package(Threads REQUIRED)
find_package(turbo REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
include_directories(${turbo_INCLUDE_DIR})

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
    set(TALLY_OS_LINUX ON)
endif ()
if (CMAKE_SYSTEM_NAME MATCHES "(Darwin|FreeBSD)")
    set(TALLY_OS_DARWIN_BSD ON)
    IF (CMAKE_SYSTEM_NAME MATCHES "(Darwin)")
        set(TALLY_OS_DARWIN ON)
    else ()
        SET(SIGAR_LINK_FLAGS "-lkvm")
    endif ()

endif ()
############################################################
#
# add you libs to the KMCMAKE_DEPS_LINK variable eg as turbo
# so you can and system pthread and rt, dl already add to
# KMCMAKE_SYSTEM_DYLINK, using it for fun.
##########################################################
set(KMCMAKE_DEPS_LINK
        turbo::turbo_static
        ${SIGAR_LINK_FLAGS}
        ${KMCMAKE_SYSTEM_DYLINK}
        )
IF (WIN32)
    set(TALLY_OS_WIN32 ON)
    list(APPEND KMCMAKE_DEPS_LINK ws2_32 netapi32 version)
endif ()
list(REMOVE_DUPLICATES KMCMAKE_DEPS_LINK)
kmcmake_print_list_label("Denpendcies:" KMCMAKE_DEPS_LINK)





